﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Dapper.Moon
{
    internal class ConstantExpressionProvider
    {
        private ExpressionProvide _expression = null;

        public ConstantExpressionProvider(ExpressionProvide expression)
        {
            _expression = expression;
        }

        /// <summary>
        /// 表示具有常数值的表达式
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        public string Resolve(Expression exp)
        {
            ConstantExpression ce = exp as ConstantExpression;
            if (ce.Value == null)
            {
                return "null";
            }
            else if (ce?.Value?.ToString() == "True")
            {
                return "1=1";
            }
            else if (ce.Value is ValueType)
            {
                //SetParameter(GetValueType(ce.Value));
                //return GetParamName();
                return _expression.GetValueType(ce.Value).ToString();
            }
            else if (ce.Value is string || ce.Value is DateTime || ce.Value is char)
            {
                //SetParameter(GetValueType(ce.Value));
                //return GetParamName();
                return $"'{_expression.GetValueType(ce.Value).ToString()}'";
            }
            return "";
        }
    }
}
